﻿ IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'ProductoGetList')
	BEGIN
		DROP  Procedure  ProductoGetList
	END
GO

CREATE PROCEDURE ProductoGetList 	
	(	
		@empresaId AS INT,
		@sucursalId AS INT,				
		@id AS VARCHAR(13) = NULL,
		@filtro AS VARCHAR(50) = NULL		
	)	
AS
BEGIN	
	SET NOCOUNT ON
	
	SELECT	A.art_id AS Id, art_nombre AS Nombre
	FROM	Articulo A
	INNER JOIN Articulo_x_Bodega AB 
		ON	A.emp_id = AB.emp_id 
		AND A.art_id = AB.art_id 	
	INNER JOIN lit_parametrosbodega P
		ON  P.EmpresaId = AB.Emp_id
		AND P.SucursalId = AB.Suc_id
		AND P.BodegaProductoTerminado = AB.Bod_id
	WHERE P.EmpresaId = @EmpresaId
	  AND P.SucursalId = @SucursalId
	  AND A.Art_Nombre like '%' + ISNULL(@filtro,'') + '%'
	  AND A.Art_Id = ISNULL(@Id, A.Art_Id) 
	  AND A.Estatus_id = 1
	ORDER BY art_nombre 
	
	SET NOCOUNT OFF
END
GO
 